<script lang="ts" setup>
	import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
	import { $http, $system, useStorage } from './utils';
	import { useWebConfigStore, useStatusStore, useUserStore } from "@/stores";
	// #ifdef H5
	import { replaceUrlParam } from '@/utils/functions'
	// #endif
	onLaunch((options : any) => {
		uni.hideTabBar();
		const storeage = useStorage();
		const appid = options.query?.appid || $system.appid();
		if (appid) {
			// #ifdef H5
			storeage.set('APPID', appid);
			// #endif
		} 
		const statusStore = useStatusStore();
		statusStore.initStatus();
		const { setWebConfig, initWebConfig } = useWebConfigStore();
		const { initUserInfo, setUserInfo } = useUserStore();
		initWebConfig();
		initUserInfo();
		$http.get('Config/getConfig').then((res : any) => {
			setWebConfig(res.data);
		});

		const icode = options.query?.icode;
		if (icode && !storeage.get('ICODE.' + appid)) {
			storeage.set('ICODE.' + appid, icode);
		}
		const puid = options.query?.puid;
		if (puid && !storeage.get('PUID.' + appid)) {
			storeage.set('PUID.' + appid, puid);
		}

		const scene = options.query?.scene;
		if (scene) {
			const sceneArr = decodeURIComponent(scene).split('&');
			const sceneObj : any = {};
			sceneArr.forEach((item : string) => {
				const arr = item.split('=');
				sceneObj[arr[0]] = arr[1];
			})
			if (sceneObj.puid) {
				storeage.set('PUID.' + appid, sceneObj.puid);
			}
		}

		let token = options.query?.token;
		if (token) {
			setUserInfo({ token: token }).then(() => {
				replaceUrlParam('token', '')
			}).catch(() => { });
		}
		console.log('App Launch')
	})
	onShow(() => {
		console.log('App Show')
	})
	onHide(() => {
		console.log('App Hide')
	})
</script>

<style lang="scss">
	// #ifdef MP-WEIXIN
	view {
		outline: none;
		box-sizing: border-box;
	}

	// #endif
	/*每个页面公共css */
	@import "static/common.scss";

	page {
		background-color: #f4f8fb;
	}

	.box-shadow {
		box-shadow: 0 0px 10px -2px rgba(42, 42, 42, 0.5);
	}

	.mb-10 {
		padding-bottom: calc(env(safe-area-inset-bottom) + 66px);
	}

	.btn-normal {
		display: block;
		margin: 0;
		padding: 0;
		line-height: normal;
		background: none;
		border-radius: 0;
		box-shadow: none;
		border: none;
		font-size: unset;
		text-align: unset;
		overflow: visible;
		color: inherit;
	}

	.btn-normal:after {
		border: none;
	}

	.btn-normal.button-hover {
		color: inherit;
	}

	button:after {
		content: none;
		border: none;
	}
</style>